package com.winchain.chainbill.tbill.basic.service.impl;

import com.shell.bee.base.exception.UnCheckException;
import com.winchain.chainbill.tbill.base.po.TbOpt;
import com.winchain.chainbill.tbill.base.po.TbRec;
import com.winchain.chainbill.tbill.base.service.TbRecService;
import com.winchain.chainbill.tbill.basic.service.TBillMoveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TBillMoveServiceImpl implements TBillMoveService {
	@Autowired
	private TbRecService tbRecService;

	public void move(TbRec bill, TbOpt opt) {
		String curState = opt.getCurState();
		String nextState = opt.getNxtState();
		if ("S000".equals(curState)) {
			bill.setBillState(nextState);
			this.tbRecService.save(bill);
			return;
		}
		bill.setCurBillState(curState);
		bill.setBillState(nextState);
		int affectedRows = this.tbRecService.updateBillOptimistically(bill);
		if (affectedRows != 1) {
			throw new UnCheckException("����������������������");
		}
	}
}
